package com.cictec.middleware.elasticsearch.camel;

import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultProducerTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.cictec.middleware.elasticsearch.camel.processor.MiddlewareMileageCaculateSaveESProcessor;
import com.cictec.middleware.elasticsearch.camel.processor.MiddlewareRealCaculateSaveESProcessor;

//START SNIPPET: RouteConfig
/**
 * A simple example router from a file system to an ActiveMQ queue and then to a
 * file system
 *
 * @version
 */
@Configuration
public class ElasticsearchCamelConfig extends RouteBuilder {

	@Bean
	public ProducerTemplate producerTemplate(CamelContext camelContext) throws Exception {
		ProducerTemplate template = new DefaultProducerTemplate(camelContext);
//		template.setDefaultEndpointUri("seda:middleware.real.save.es");
		// seda://middle.real.caculate.save.es
		template.start();
		return template;
	};
	
	
	@Bean(name = "realCaculateProducerTemplate")
	public ProducerTemplate realCaculateProducerTemplate(CamelContext camelContext) throws Exception {
		ProducerTemplate template = new DefaultProducerTemplate(camelContext);
		template.setDefaultEndpointUri("seda:middleware.real.save.es");
		// seda://middle.real.caculate.save.es
		template.start();
		return template;
	};

	@Bean(name = "busMileageProducerTemplate")
	public ProducerTemplate busMileageProducerTemplate(CamelContext camelContext) throws Exception {
		ProducerTemplate template = new DefaultProducerTemplate(camelContext);
		template.setDefaultEndpointUri("seda:middleware.caculate.save.es");
		template.start();

		return template;
	};
	
	@Autowired
	private MiddlewareMileageCaculateSaveESProcessor middlewareMileageCaculateSaveESProcessor;
	@Autowired
	private MiddlewareRealCaculateSaveESProcessor middlewareRealCaculateSaveESProcessor;

	@Override
	public void configure() throws Exception {
		// you can configure the route rule with Java DSL here

		// populate the message queue with some messages
		from("seda:middleware.real.save.es").process(middlewareRealCaculateSaveESProcessor).id("realCaculate"); // 实时计算路由
		from("seda:middleware.caculate.save.es").process(middlewareMileageCaculateSaveESProcessor).id("busMileageCaculate"); // 里程计算路由
		from("seda:middleware.tm.save.es").process(middlewareMileageCaculateSaveESProcessor).id("busMileageCaculate"); // 原始GPS位置信息

	}

}